package com.tarena.security.admin.controller;

import com.tarena.security.admin.assemble.DepartmentAssemble;
import com.tarena.security.admin.entity.db.Department;
import com.tarena.security.admin.entity.param.DepartmentParam;
import com.tarena.security.admin.entity.query.DepartmentQuery;
import com.tarena.security.admin.result.JsonResult;
import com.tarena.security.admin.service.IDepartmentService;
import com.tarena.security.admin.vo.DepartmentVO;
import com.tedu.inn.protocol.validation.group.Create;
import com.tedu.inn.protocol.validation.group.Update;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Ly
 * @since 2023-04-10
 */
@RestController
@Api(tags = "department")
@RequestMapping("/department")
public class DepartmentController {
    @Resource
    private IDepartmentService departmentService;

    @Resource
    private DepartmentAssemble departmentAssemble;

    @PostMapping("/add-new")
    @ApiOperation("新增Department")
    public JsonResult<String> addNewDepartment(@Validated(Create.class) DepartmentParam departmentParam){
        departmentService.addNewDepartment(departmentParam);
        return JsonResult.ok("新增成功");
    }
    @ApiOperation("获取Department列表")
    @GetMapping("/get-Department-List")
    public JsonResult<List<DepartmentVO>> getAppList(DepartmentQuery departmentQuery){
        List<Department> list=departmentService.getDepartmentList(departmentQuery);
        List<DepartmentVO> vos = departmentAssemble.assembleDtosToVos(list);
        return JsonResult.ok(vos);
    }

    @ApiOperation("修改Department")
    @PostMapping("/update")
    public JsonResult<String> updateDepartment(@Validated(Update.class) DepartmentParam departmentParam){
        departmentService.updateByID(departmentParam);
        return JsonResult.ok("修改成功");
    }

    @ApiOperation("根据ID获取Department")
    @GetMapping("/getById/{id}")
    public JsonResult<DepartmentVO> getAppById(@PathVariable Integer id){
        Department department=departmentService.getDepartmentById(id);
        DepartmentVO vo = departmentAssemble.assembleDtosToVo(department);
        return JsonResult.ok(vo);
    }

    @ApiOperation("根据ID删除Department")
    @PostMapping("/deleteById")
    public JsonResult<String> deleteAppById(Integer ... id){
        departmentService.deleteDepartmentById(id);
        return JsonResult.ok("删除成功");
    }
}
